//
//  MQStatusCell.swift
//  SinaWeiBo
//
//  Created by 毛强 on 16/1/20.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit
import SnapKit

let MQStatusCellMargin:CGFloat = 10
let MQStatusCellIconSize:CGFloat = 35

class MQStatusCell: UITableViewCell {
    
    var statusToolBarTopConstraint:Constraint?
    var statusViewModel:MQStatusViewModel?{
        didSet{
            statusOriginalView.statusViewModel = statusViewModel
            statusToolBar.statusViewModel = statusViewModel
            
            statusToolBarTopConstraint?.uninstall()
            
            if statusViewModel?.status?.retweeted_status != nil{
                //有转发微博
                statusReweetedView.hidden = false
                statusReweetedView.statusViewModel = statusViewModel
                statusToolBar.snp_updateConstraints(closure: { (make) -> Void in
                 statusToolBarTopConstraint = make.top.equalTo(statusReweetedView.snp_bottom).constraint
                })
            }else{
                //无转发微博
                statusReweetedView.hidden = true
                statusToolBar.snp_updateConstraints(closure: { (make) -> Void in
                statusToolBarTopConstraint = make.top.equalTo(statusOriginalView.snp_bottom).constraint
                })
            }
        }
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .None
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        contentView.addSubview(statusOriginalView)
        contentView.addSubview(statusReweetedView)
        contentView.addSubview(statusToolBar)
        
        
        //设置约束
        statusOriginalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView).offset(MQStatusCellMargin)
            make.leading.equalTo(contentView)
//            make.bottom.equalTo(contentView)
            make.trailing.equalTo(contentView)
//            make.height.equalTo(80)
        }
        
        statusReweetedView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentView)
            make.top.equalTo(statusOriginalView.snp_bottom)
            make.trailing.equalTo(contentView)
//            make.height.equalTo(80)
        }
        
        statusToolBar.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentView)
           self.statusToolBarTopConstraint = make.top.equalTo(statusReweetedView.snp_bottom).constraint
            make.trailing.equalTo(contentView)
            make.height.equalTo(44)
        }
        contentView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(statusToolBar.snp_bottom)
        }
        
    }
    
    private lazy var statusOriginalView:MQStatusOriginalView = MQStatusOriginalView()
    private lazy var statusToolBar:MQStatusToolBar = MQStatusToolBar()
    private lazy var statusReweetedView:MQStatusRetweetedView = MQStatusRetweetedView()
}
